package org.example.notificationservice.consumer;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.example.notificationservice.entity.Notification;
import org.example.notificationservice.service.NotificationService;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RequiredArgsConstructor
public class NotificationConsumer {
    private final NotificationService notificationService;

    @KafkaListener(topics = "${kafka.topics.notifications}")
    public void handleNotification(Notification notification) {
        try {
            notificationService.sendNotification(notification);
        } catch (Exception e) {
            log.error("Failed to process notification", e);
        }
    }
}